"""
File: web_util.py
Author: ershixiong
Date: 2023/11/22
describe:

"""
from selenium_demo01.litemall_demo_po.utils.log_utils import logger


def click_exception(by, locator, max_attempts=15):
    def _inner(driver):

        actual_attempts = 0
        while actual_attempts < max_attempts:
            actual_attempts += 1
            try:
                driver.find_element(by, locator).click()
                return True
            except Exception:
                logger.info('点击时报错')
        raise Exception('超过最大点击次数')

    return _inner
